package com.swordget.entity.vo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.swordget.exception.VerifyFailException;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: David
 * @Date: Created in 16:53 2020/4/7
 * @Description: 简单分页vo
 * @Modified By:
 * @Version: 0.0.1
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SimplePageRequestVo<T> {

    /**
     * 每页的条数
     */
    private int rows;

    /**
     * 页号
     */
    private int page;

    /**
     * 表标识号
     */
    private String tableId;

    /**
     * 执行操作的用户
     */
    private String loginId;

    /**
     * 是否显示隐藏字段
     */
    private boolean showHide;

    /**
     * 是否显示业务字段
     */
    private boolean showBusiness;

    /**
     * 数据状态
     */
    private String dataStatus;

    /**
     * 表名
     */
    private String tableEn;

    /**
     * 表中文名
     */
    private String tableCn;

    /**
     * 封装查询条件
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String searchParams;

    @JsonIgnore
    private JSONArray queryParams;

    @JsonIgnore
    private int start;

    @JsonIgnore
    private int end;

    public JSONArray getQueryParams() {
        if (this.queryParams == null && StringUtils.isNotBlank(searchParams)) {
            try {
                this.queryParams = JSONObject.parseArray(searchParams);
            } catch (Exception e) {
                throw new VerifyFailException("请检查您的参数!", e);
            }
            this.searchParams = null;
        }
        return this.queryParams;
    }
}
